<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="initial-scale=1, maximum-scale=1, user-scalable=no">
    <meta name="format-detection" content="telephone=no">
    <title>我的投诉</title>
    <link rel="stylesheet" href="css/frozen.css">
    <style type="text/css">.ui-grid-halve-img span a { display: block; width: 100%; height: 100%; cursor: pointer; } .content { position: relative; font-size: 16px; padding-right: 15px; padding-left: 15px; height: 100%; } textarea { resize: none; } </style>
</head>
<body class="body_bg" ontouchstart>
<header class="ui-header ui-header-positive ui-border-b"><i class="ui-icon-return"></i> <h1>我要投诉</h1> <div class="admin_ico"></div> </header>
<section class="ui-container">
    <div class="ui-form-item ui-form-item-show ui-border-b bg_fff"><label for="#">投诉主题：</label> <input id="subject" type="text" name="subject" placeholder="请输入投诉主题" maxlength="20"> </div>
    <div class="ui-form-item ui-form-item-textarea ui-border-b bg_fff content"><label for="#" style="color: #666;">投诉内容：</label> <textarea id="content" name="content" placeholder="请填写的信息在100字以内" rows="6" maxlength="100"></textarea> </div>
    <div class="ui-form-item ui-form-item-show ui-border-b bg_fff"><label for="#">匿名发布：</label> <label class="ui-switch" style="left: 108px;"> <input id="anonymous" name="anonymous" type="checkbox" checked="checked"> </label> </div>
    <div class="ui-btn-wrap" id="btn-submit"> <button class="ui-btn-lg ui-btn-primary"> 提交</button> </div>
</section>
<div class="ui-dialog"> <div class="ui-dialog-cnt"> <header class="ui-dialog-hd ui-border-b"><h3>温馨提示</h3> <i class="ui-dialog-close" data-role="button"></i> </header> <div class="ui-dialog-bd"> <div>您的投诉提交过于频繁！</div> </div> <div class="ui-dialog-ft"> <button type="button" data-role="button">关闭</button> </div> </div> </div>
<script src="js/zepto.min.js"></script>
<script src="js/frozen.js"></script>
<script src="js/oceansoft.util-1.0.js"></script>
<script type="text/javascript">
    var subject, content, anonymous, toast;
    var session;
    try { session = Oceansoft.session(); } catch (ex) { }
    var local = JSON.parse(localStorage.getItem("os.ga.api"));
    $("#btn-submit").tap(function () {
        subject = $.trim($("#subject").val());
        if (!subject) {
            toast = $.tips({content: '请输入投诉主题', stayTime: 1500, type: 'warn'});
            return false;
        }
        content = $.trim($("#content").val());
        if (!content) {
            $.tips({content: '请输入投诉内容', stayTime: 1500, type: 'warn'});
            return false;
        }
        if (!session) {
            $.dialog({
                title: '温馨提示',
                content: '获取用户登录信息失败!',
                button: ["确认", "取消"]
            });
            return false;
        }
        if (local) {
            var now = new Date().getTime();
            if ('complain' == local.m && (now - local.t < 300000 && local.c > 2)) { //300s两次
                $(".ui-dialog").dialog("show");
                return false;
            }
        }
        var dlg, data = $.map({ 'uid': session.uid, 'name': session.userName, 'subject': subject, 'content': content, 'anonymous': document.getElementById("anonymous").checked ? 1 : 0}, function (item, index) { return index + '=' + item; }).join("&");
        $.ajax({
            type: 'post',
            url: 'http://172.17.150.108:8080/econsole/api/wechat/v1/complain',
            data: data,
            dataType: 'json',
            timeout: 3000,
            beforeSend: function (xhr, settings) {
                dlg = $.loading({content: '正在提交'});
            },
            success: function (data) {
                dlg.loading("hide");
                if (data && data.succ) {
                    local = {
                        'm': 'complain',
                        't': new Date().getTime(),
                        'c': local && local.c ? (local.c + 1) : 1
                    };
                    localStorage.setItem("os.ga.api", JSON.stringify(local));
                    $("#subject,#content").val("");
                    $.tips({content: data.msg, stayTime: 1500, type: 'info'});
                } else {
                    $.tips({content: '提交失败', stayTime: 1500, type: 'info'});
                }
            },
            error: function (xhr, type) {
                dlg.loading("hide");
                $.tips({content: '提交失败', stayTime: 1500, type: 'info'});
            }
        });
        return false;
    });
</script>
</body>
</html>